//
//  WidgetViewModel.swift
//  WidgetExample
//
//  Created by Ben on 2022/4/17.
//  Copyright © 2022 Ben. All rights reserved.
//

import Foundation
import Combine
import WidgetKit
import WidgetExtensionExtension

class WidgetViewModel: ObservableObject {
    private var cancellableBag = Set<AnyCancellable>()

    @Published var timeWidgetShowWeek: Bool = true
    
    init() {
        
        $timeWidgetShowWeek
            .dropFirst()
            .sink { value in
                print(value)
                UserDefaultGroup.shared.timeWidgetShowWeek = value
                WidgetCenter.shared.reloadTimelines(ofKind: WidgetType.time.kind)
            }
            .store(in: &cancellableBag)
    }
}
